<?php 
include("common/conn.php"); 
if($_SESSION['userid']==""){
  echo "<script>window.location.href='login.php';</script>";
}
// 查询运费险
$query = mysql_query("select * from freightRisk where id<4");
while ($row = mysql_fetch_assoc($query)) {
  $freightRisk[] = $row;
}
// 查询运费险 end

// 更新运费险
if ($_POST) {
  for ($i=0; $i < 3; $i++) { 
    $query = mysql_query("UPDATE freightRisk set goodsNum=".$_POST[goodsNum][$i].",freightRisk=".$_POST[freightRisk][$i]." where id=".$_POST[id][$i]);
  }
  echo "<script>alert('修改运费险成功!');window.location.href='freightRisk.php'</script>";
}
// 更新运费险 end

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>e网批发管理后台</title>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
  <link href="css/style2.css" rel="stylesheet" type="text/css" />
</head>

<body>

  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->


  <!-- staqrt subnav -->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">
        <ul>
          <li><a href="xitong.php">热门搜索</a></li>
          <li><a href="xieyi.php">用户协议</a></li>
          <li><a href="service.php">服务中心信息</a></li>
          <li><a href="freightRisk.php" class="sub_nav_active">海淘运费险</a></li>
          <li><a href="fanquan.php">平台返券</a></li>
          <li><a href="erweima.php">二维码</a></li>
        </ul>

      </div>

    </div>


  </div>
  <div class="container_12">
    <form action="" method="post" class="form" > 
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="50%" scope="col">
            <label>商品件数</label>
            <input name="goodsNum[]" type="text" class="text"  value="<?php echo $freightRisk[0][goodsNum];?>"/>
            <label>件</label>
          </td>

          <td width="50%" scope="col">
            <label>运费险</label>
            <input name="freightRisk[]" class="freightRisk" type="text" class="text"  value="<?php echo $freightRisk[0][freightRisk];?>"/>
            <label>元</label>
          </td>
          <input type="hidden" name="id[]" value="<?php echo $freightRisk[0][id]; ?>">
        </tr>

        <tr>
          <td width="50%" scope="col">
            <label>商品件数</label>
            <input name="goodsNum[]" type="text" class="text"  value="<?php echo $freightRisk[1][goodsNum];?>"/>
            <label>件</label>
          </td>

          <td width="50%" scope="col">
            <label>运费险</label>
            <input name="freightRisk[]" class="freightRisk" type="text" class="text"  value="<?php echo $freightRisk[1][freightRisk];?>"/>
            <label>元</label>
          </td>

          <input type="hidden" name="id[]" value="<?php echo $freightRisk[1][id]; ?>">
        </tr>

        <tr>
          <td width="50%" scope="col">
            <label>商品件数</label>
            <input name="goodsNum[]" type="text" class="text"  value="<?php echo $freightRisk[2][goodsNum];?>"/>
            <label>件以上</label>
          </td>

          <td width="50%" scope="col">
            <label>运费险</label>
            <input name="freightRisk[]" class="freightRisk" type="text" class="text"  value="<?php echo $freightRisk[2][freightRisk];?>"/>
            <label>元</label>
          </td>

          <input type="hidden" name="id[]" value="<?php echo $freightRisk[2][id]; ?>">
        </tr>


        <tr>
          <td width="40%" scope="col"></td>
          <td width="50%" scope="col">
            <input name="" type="button" value="提交" class="submit" />
          </td>
        </tr>
        </table>

      </form>
    </div>
</body>
<script type="text/javascript">
  // 验证价格
  function checkPrice(price) {
    if (!(/^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/.test(price))) {
      return false;
    } else {
      return true;
    }
  }
  // 验证价格 end
  $('input[type="button"]').click(function(){
    var price = $('.freightRisk');
    var flag = true;
    price.each(function(){
      var check = checkPrice($(this).val());
      if (!check) {
        flag = false;
      }
    })
    if (!flag) {
      alert('价格输入有误');
    }else{
      $('.form').submit();
    }
  })
</script>
</html>
